package struts.action;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import struts.bean.ActionForm;
import struts.bean.LoginBean;
import struts.service.LoginService;
import struts.service.LoginServiceImpl;

public class LoginAction implements Action {

	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response, ActionForm form, Map<String, String> forwards) {

//		LoginBean loginbean = new LoginBean();
//		String username = request.getParameter("username");
//		String url = "";
//		if (username.equals("shi")) {
//			loginbean.setSex("nan");
//			loginbean.setUsername(username);
//			url = "/view/success.jsp";
//		}
//		else
//		{
//			loginbean.setSex("nv");
//			loginbean.setUsername(username);
//			url = "/view/failture.jsp";
//		}
		String url = "";
		LoginService service = new LoginServiceImpl();
		Map<String, LoginBean> map = service.getLoginMessage(request.getParameter("username"));
		Set<String> set = map.keySet();
		for (Iterator<String> it = set.iterator(); it.hasNext();) {
			url = it.next();
		}
		request.setAttribute("loginMessage", map.get(url));
		request.setAttribute("username", map.get(url).getUsername());
		request.setAttribute("sex", map.get(url).getSex());
		
		return url;
	}
}
